package com.lightheart.sphr.xiaobinggan.logo

import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.util.Log
import android.view.View
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.widget.ImageView
import com.lightheart.sphr.xiaobinggan.R
import com.lightheart.sphr.xiaobinggan.base.BaseActivity
import com.lightheart.sphr.xiaobinggan.module.home.presenter.HomePresenter
import kotlinx.android.synthetic.main.activity_logo.*
import kotlinx.android.synthetic.main.common_toolbar.*


class LogoActivity : BaseActivity<HomePresenter>() {

    lateinit var mAnimation: Animation

    override fun getLayoutId() = R.layout.activity_logo

    override fun initInjector() {
    }

    override fun initView() {
        initToolbar(common_toolbar, common_toolbar_title_tv, bt_sub, R.string.login_anim, false, R.string.register)

        val mAnimationView: ImageView = findViewById<View>(R.id.iv) as ImageView
        mAnimation = AnimationUtils.loadAnimation(this, R.anim.anim_score)
        mAnimationView.startAnimation(mAnimation)

        anim_logo.addOffsetAnimListener(object : AnimatorListenerAdapter() {
            override fun onAnimationEnd(animation: Animator) {
                Log.d("AnimLogoView", "Offset anim end")
            }
        })
        anim_logo.addGradientAnimListener(object : AnimatorListenerAdapter() {
            override fun onAnimationEnd(animation: Animator) {
                Log.d("AnimLogoView", "Gradient anim end")
            }
        })
        anim_logo.startAnimation()

        iv.setOnClickListener {
            mAnimation.cancel()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        mAnimation.cancel()
    }
}